package com.jss.lanouhn.fristapp.adapters;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jss.lanouhn.fristapp.R;
import com.jss.lanouhn.fristapp.activity.SelecterDetails;
import com.jss.lanouhn.fristapp.modles.SelecterSampleImgInfo;
import com.makeramen.roundedimageview.RoundedImageView;
import com.squareup.picasso.Picasso;

/**
 * Created by lanouhn on 16/9/5.
 */
public class RvlAdapter extends RecyclerView.Adapter<RvlAdapter.LikesViewHolder>{
    private SelecterSampleImgInfo selecterSampleImgInfo;
    private Context context;

    public RvlAdapter(SelecterSampleImgInfo selecterSampleImgInfo, Context context) {
        this.selecterSampleImgInfo = selecterSampleImgInfo;
        this.context = context;
    }

    @Override
    public LikesViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=LayoutInflater.from(context).inflate(R.layout.item_selecter_likes,null);
        LikesViewHolder holder=new LikesViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(LikesViewHolder holder, int position) {
        final SelecterSampleImgInfo.DataBean.RecommendItemsBean bean=
                selecterSampleImgInfo.getData().getRecommend_items().get(position);
        Picasso.with(context).load(bean.getCover_image_url()).into(holder.riv);
        holder.tv_title.setText(bean.getName());
        holder.tv_money.setText("￥"+bean.getPrice());

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context,SelecterDetails.class);
                intent.putExtra("id",bean.getId()+"");
                intent.putExtra("url",bean.getPurchase_url());
                context.startActivity(intent);
            }
        });




    }

    @Override
    public int getItemCount() {
        return selecterSampleImgInfo.getData().getRecommend_items().size();
    }

    public class LikesViewHolder extends RecyclerView.ViewHolder {
        private RoundedImageView riv;
        private TextView tv_title,tv_money;
        public LikesViewHolder(View itemView) {
            super(itemView);
            riv= (RoundedImageView) itemView.findViewById(R.id.riv_sample_likes);
            tv_title= (TextView) itemView.findViewById(R.id.tv_rvitem_likes);
            tv_money= (TextView) itemView.findViewById(R.id.tv_rvitem_money);
        }
    }
}
